import { createStore } from "vuex";

const store = createStore({
    state () {
        return {
            bookManageToken: "",
            userInfo: {},
            requestUrl: "http://localhost:9000/manage"
        }
    },
    mutations: {
        SET_TOKEN: (state,token)=>{
            state.bookManageToken = token;
            localStorage.setItem("bookManageToken",token);
        },
        SET_USERINFO: (state,userInfo)=>{
            state.userInfo = userInfo;
            sessionStorage.setItem("userInfo",JSON.stringify(userInfo));
        },
        REMOVE_INFO:(state)=>{
            state.userInfo = {};
            state.bookManageToken = "";
            localStorage.setItem("bookManageToken","");
            sessionStorage.setItem("userInfo","");
        }
    },
    getters: {
        getUser: state => {
            return state.userInfo;
        },
        getRequestUrl: state => {
            return state.requestUrl
        },
        getToken: state => {
            return localStorage.getItem("bookManageToken")
        },
    },
    modules: {
    }
});

export default store;
